package com.juli.school.app.controller;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.juli.school.dao.entity.Help;
import com.juli.school.service.impl.HelpService;

/**
 *  帮助
 * @author: hantao
 * @since: 2018年3月19日 
 */
@RequestMapping(value = "/help")
@Controller
public class HelpController {

	@Resource
	private HelpService helpService;
	
	@RequestMapping("/helpindex")
	public String helpindex(ModelMap model) {
		//查询一级菜单常见问题
		List<Help> comlist = helpService.getComques();
		//查询热门问题
		List<Help> hotlist = helpService.getHotques();
		model.put("comlist", comlist);
		model.put("hotlist", hotlist);
		return "help/index";
	}
	
	/**  
	 * @Description： 查询具体某一类常见问题
	 * @author: hantao
	 * @since: 2018年3月25日 上午9:04:54  
	 */
	@RequestMapping("/comquery")
	public String comquery(ModelMap model, String parentnode) {
		Integer node = Integer.valueOf(parentnode);
		List<Help> comlist = helpService.comquery(node);
		Help obj = helpService.getById(node);
		model.put("comlist", comlist);
		model.put("obj", obj);
		return "help/detail";
	}
	
	/**  
	 * @Description： 点击量加一
	 * @author: hantao
	 * @since: 2018年3月25日 上午9:24:25  
	 */
	@RequestMapping("/click")
	@ResponseBody
	public String click(String id) {
		Integer node = Integer.valueOf(id);
		Help obj = helpService.getById(node);
		if(StringUtils.isEmpty(obj.getClickrate())){
			obj.setClickrate("0");
		}
		Integer click = Integer.valueOf(obj.getClickrate());
		obj.setClickrate(String.valueOf(click+1));
		helpService.click(obj);
		return "1";
	}
}
